//
// Created by 吴锐 on 2022/2/26.
//

#include "iostream"

using namespace std;

class Animal {
public:
    Animal(){
        cout << "Animal的构造函数" << endl;
    }

    virtual void speak() = 0;

//    virtual ~Animal(){
//        cout << "Animal的析构函数调用" << endl;
//    }

    virtual ~Animal() = 0;
};
Animal::~Animal() {
    cout << "Animal纯虚析构函数调用" << endl;
}

class Cat : public Animal {
public:
    string* name;

    Cat(){
    }

    Cat(string name){
        cout << "Cat的构造函数的调用" << endl;
        this->name = new string(name);
    }

    virtual void speak(){
        cout << *this->name << "小猫在说话" << endl;
    }

    ~Cat(){
        if(this->name != NULL){
            cout << "Cat的析构函数的调用" << endl;
            delete this->name;
            this->name = NULL;
        }
    }
};

void test01(){
    Animal* animal = new Cat("tom");
    animal->speak();
    delete animal;
}

int main(){
    test01();
    return 0;
}